<script setup lang="ts">
import { type UploadUserFile } from 'element-plus';
import { defineAsyncComponent, ref } from 'vue';

import { httpRequestService } from '@/shared/http/http-request-service';

const EChart = defineAsyncComponent(() => import('@/shared/components/EChart.vue'));
const fileList = ref<UploadUserFile[]>([]);

function startUpload(): void {
  const files = [];

  for (const file of fileList.value) {
    files.push(file.raw);
  }

  httpRequestService.upload('/file/upload', {
    data: { id: 'posted-id-value', files: files },
  });
}
</script>

<template>
  <div>HOME</div>
  <EChart
    :option="{
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
      },
      yAxis: {
        type: 'value',
      },
      series: [
        {
          data: [150, 230, 224, 218, 135, 147, 260],
          type: 'line',
        },
      ],
    }"
  />

  <div>
    <el-upload v-model:file-list="fileList" :auto-upload="false">
      <template #trigger>
        <el-button type="primary">select file</el-button>
      </template>
      <el-button class="ml-3" type="success" @click="startUpload()">
        upload to server
      </el-button>
    </el-upload>
  </div>
</template>

<style scoped></style>
